package org.jobtask.ui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

public class StartMenuButton extends JLabel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -8301483879200637588L;
	
	private JPopupMenu startMenu=null;
	
	public void addMenu(JMenuItem item){
		this.startMenu.add(item);
	}
	
	public void addSeparator(){
		this.startMenu.addSeparator();
	}
	
	public StartMenuButton(){
		this.setIcon(new ImageIcon(this.getClass().getResource("images/startMenu.png")));
		this.addMouseListener(new MenuButtonInnerListener());
		this.startMenu=new JPopupMenu();
	}

	
	private class MenuButtonInnerListener implements MouseListener{

		@Override
		public void mouseClicked(MouseEvent e) {
		}

		@Override
		public void mousePressed(MouseEvent e) {
			if(e.getButton()==MouseEvent.BUTTON1){
				setIcon(new ImageIcon(this.getClass().getResource("images/startMenu-down.png")));
				startMenu.show(StartMenuButton.this,-93,-260);
			}
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			setIcon(new ImageIcon(this.getClass().getResource("images/startMenu-over.png")));
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			setIcon(new ImageIcon(this.getClass().getResource("images/startMenu-over.png")));
		}

		@Override
		public void mouseExited(MouseEvent e) {
			setIcon(new ImageIcon(this.getClass().getResource("images/startMenu.png")));
		}
	}
}
